/*******************************************************************************
Project:		Wealth -- Smith, Zidar, and Zwick
Last modified: 	2021-02-02
Modified by:	Dustin Swonder
Description:	This file creates a .dta file containing a series of aggregate 
				wealth of the Forbes 400 for SCF years. To see press releases, 
				see folder ~/Dropbox/wealth/data/forbesmedia
*******************************************************************************/

/*******************************************************************************
	(1) Enter assumed Forbes 400 net worth values from April 2020 draft; 
		2019 aggregate wealth is not in that draft.
*******************************************************************************/

clear
set obs 11

qui gen year = 1986 + _n * 3
assert inrange(year, 1989, 2019)

#delimit ;
qui gen forbeswlth = cond(year == 1989, 2.68E11,
					 cond(year == 1992, 3.01E11,
					 cond(year == 1995, 3.94E11,
					 cond(year == 1998, 7.38E11,
					 cond(year == 2001, 9.51E11,
					 cond(year == 2004, 1.005E12, 
					 cond(year == 2007, 1.54E12,
					 cond(year == 2010, 1.37E12,
					 cond(year == 2013, 2E12, 
					 cond(year == 2016, 2.4E12, 
					 cond(year == 2019, 2.96E12, .n)))))))))));
#delimit cr
assert !missing(forbeswlth)

#delimit ;
qui gen forbes_threshold = cond(year == 1989, 2.75E8,
					 cond(year == 1992, 2.65E8,
					 cond(year == 1995, 3.45E8, /* Ian Cumming, or Oakleigh Blakeman Thorne */
					 cond(year == 1998, 5E8, /* Grover Connell; or Ernest Gallos */
					 cond(year == 2001, 6E8, 
					 cond(year == 2004, 7.5E8, 
					 cond(year == 2007, 1.3E9,
					 cond(year == 2010, 1E9,
					 cond(year == 2013, 1.3E9,
					 cond(year == 2016, 1.7E9, 
					 cond(year == 2019, 2.1E9, .n)))))))))));
#delimit cr
assert !missing(forbes_threshold)

sort year

label variable forbeswlth "Nominal aggregate wealth of the Forbes 400"
label variable forbes_threshold "Minimum wealth of Forbes 400 individuals"

qui save $dtadir/forbeswlth.dta, replace

/*******************************************************************************
	(2) Validate that these numbers are sane by looking at different estimates
*******************************************************************************/

	/***************************************************************************
		(2.1) Compare with aggregates from Forbes microfile on Open Policy 
			Analysis wealth tax scoring Github page from SZ
	***************************************************************************/

use $litroot/SZ2019_BPEA/forbes_20112018_bdays.dta, clear

collapse (sum) net_worthmillions (min) forbes_threshold_microfile = net_worthmillions, by(forbes_yr)

qui gen forbeswlth_microfile = net_worthmillions * 1E6
qui replace forbes_threshold_microfile = forbes_threshold_microfile * 1E6
rename forbes_yr year

qui merge 1:1 year using $dtadir/forbeswlth.dta

assert _merge == 1 if mod(year - 1989, 3) != 0
assert _merge == 2 if !inrange(year, 2011, 2018)
assert _merge == 3 if inrange(year, 2011, 2018) & mod(year - 1989, 3) == 0
qui drop if _merge != 3
drop _merge

assert inrange(forbeswlth_microfile / forbeswlth, 0.985, 1.015)
assert forbes_threshold_microfile == forbes_threshold

	/***************************************************************************
		(2.2) Compare to aggregates obtained by applying SZ estimate of Forbes 
			share of wealth to total wealth in corresponding estimates
	***************************************************************************/

		/***********************************************************************
			(2.2.1) Parameters file aggregates from SZ
		***********************************************************************/

insheet using "$dinadir/archive_files_2019_10_14/PSZ2017Programs/parameters.csv", clear

keep yr ttwealth
rename yr year

qui replace ttwealth = ttwealth * 1E6 // Scale into dollars from millions

tempfile szparameters
qui save `szparameters'

		/***********************************************************************
			(2.2.2) Aggregate and average Forbes wealth according to SZ, 
				computed using ttwealth from parameters.csv and Forbes wealth 
				shares in SZ figures data.
		***********************************************************************/

import excel using $litroot/SZ2019_taxjusticenow/TablesFigures/SZ2019MainFigures.xlsx, ///
	sheet(DataF8c) cellrange(A8:B44) clear

rename (A B) (year forbeswlthshare)

merge 1:1 year using `szparameters', keepusing(ttwealth) assert(2 3) keep(3) nogen

gen forbeswlth_szparameters = forbeswlthshare * ttwealth

		/***********************************************************************
			(2.2.3) Merge on estimates from section 1
		***********************************************************************/

merge 1:1 year using $dtadir/forbeswlth.dta
assert _merge == 1 if mod(year - 1989, 3) != 0
assert _merge == 2 if year == 2019
assert _merge == 3 if mod(year - 1989, 3) == 0 & inrange(year, 1989, 2018)

keep if _merge == 3
drop _merge

gen szratio = forbeswlth / forbeswlth_szparameters // These are a bit high, not sure why
